// axios.defaults.baseURL='http://www.liulongbin.top:3007'
$(function () {
  getUserInfo()

  //退出登录
  $('#logout').on('click', function () {
    layer.confirm('是否确认退出？', { icon: 3, title: '提示' }, function (index) {
      //do something
      location.href = '/login.html'
      localStorage.removeItem('token')
      layer.close(index);
    })
  })





})
function getUserInfo() {
  axios({
    url: '/my/userinfo',
    method: 'get',
    // headers: {
    //   Authorization: localStorage.getItem('token')
    // }
  }).then(res => {
    //成功回调
    console.log(res.data)
    if (res.data.status != 0) {
      return laiyu.layer.msg(res.data.message)
    }
    renderAvatar(res.data.data)
  })
}
function renderAvatar(user) {
  $('.welcome').html(user.nickname || user.username)
  if (user.user_pic !== null) {
    $('.avatar-text').hide()
    $('.layui-nav-img').show().attr('src', user.user_pic)
  } else {
    let first = user.nickname[0].toUpperCase()
    $('.layui-nav-img').hide()
    $('.avatar-text').show().html(first)
  }
}